﻿var personnelId;
$(function () {
    personnelId = $("#hdnPersonnelId").val();

    $("#sex").ligerComboBox({
        cancelable: false,
        width: 50,
        valueFieldID: 'hdnSex'
    });

    $("#nation").ligerComboBox({
        cancelable: false,
        width: 50,
        url: "/Personnel/EditPersonnel/GetNationList?ram" + Math.random(),
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnNation',
        selectBoxWidth: 100
    });

    $("#hireType").ligerComboBox({
        cancelable: false,
        width: 185,
        valueFieldID: 'hdnHireType'
    });

    $("#politicalStatus").ligerComboBox({
        cancelable: false,
        width: 110,
        valueFieldID: 'hdnPoliticalStatus'
    });

    $("#education").ligerComboBox({
        cancelable: false,
        width: 110,
        valueFieldID: 'hdnEducation'
    });

    $("#maritalStatus").ligerComboBox({
        cancelable: false,
        width: 110,
        valueFieldID: 'hdnMaritalStatus'
    });

    $("#shoeSize").ligerComboBox({
        cancelable: false,
        width: 185,
        valueFieldID: 'hdnShoeSize'
    });

    $("#inServiceStatus").ligerComboBox({
        cancelable: false,
        width: 185,
        valueFieldID: 'hdnInServiceStatus'
    });

    $("#nursingAge").ligerComboBox({
        cancelable: false,
        width: 110,
        valueFieldID: 'hdnNursingAge'
    });

    //$("#jobCode").ligerComboBox({
    //    url: "/Personnel/EditPersonnel/GetJoblist?isAll=1&ram" + Math.random(),
    //    cancelable: false,
    //    width: 110,
    //    valueField: "JobCode",
    //    textField: "JobTitle",
    //    valueFieldID: 'hdnJobCode'
    //});

    $("#positionCode").ligerComboBox({
        url: "/Personnel/EditPersonnel/GetPositionlist?isAll=1&ram" + Math.random(),
        cancelable: false,
        width: 110,
        valueField: "PositionCode",
        textField: "PositionTitle",
        valueFieldID: 'hdnPositionCode'
    });

    $("#energyLevel").ligerComboBox({
        cancelable: false,
        width: 110,
        valueFieldID: 'hdnEnergyLevel'
    });

    $("#txtBirthday,#txtInDate,#txtNursingStartDate").ligerDateEditor({
        showTime: false,
        format: "yyyy-MM-dd",
        width: 110,
        cancelable: false
    });

    $("[tab='uploadFile']").each(function () {
        upload($(this).attr("id"));
    });

    bindDelFile();

    if ($("#hdnPageType").val() == 0) {
        $("#btnBack").hide();
    }
    $("#btnBack").click(function () {
        var pageType = $("#hdnPageType").val();
        if (pageType == 1) {
            location.href = "/Personnel/PersonnelList";
        }
        if (pageType == 2) {
            location.href = "/Personnel/PersonnelReview";
        }
    });

    bindPersonnel();

    bingImgShow();

    $(".lift").children().eq(0).addClass("current");
});

function getPersonnelNo() {
    $.ajax({
        url: "/Personnel/EditPersonnel/GetPersonnelNo",
        type: "post",
        data: {},
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                $("#txtPersonnelNo").val(d.Body);
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}

function bindPersonnel() {
    var flag = false;
    $.ajax({
        url: "/Personnel/EditPersonnel/GetPersonnelInfo?ram" + Math.random(),
        type: "post",
        async: false,
        data: { id: personnelId },
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                var personnel = d.Body.P_Personnel;
                if (personnel.Status != $("#hdnStatus").val() && personnelId != 0) {
                    $("#pageloading").hide();
                    $.ligerDialog.error("档案状态已改变！");
                    setTimeout(function () { $("#btnBack").click(); }, 1000);
                    return;
                }
                else {
                    $("#hdnStatus").val(personnel.Status);
                    getStatusName(personnel.Status);
                }
                if (personnel.Status != 0 || personnel.Status != 4) {
                    if (personnel.ReviewReason != null && personnel.ReviewReason != "") {
                        $("#fontReviewReason").text("护士长审核：" + personnel.ReviewReason);
                    }
                    if (personnel.ReviewReason1 != null && personnel.ReviewReason1 != "") {
                        $("#fontReviewReason1").text("护理部审核：" + personnel.ReviewReason1);
                    }
                }
                personnelId = personnel.Id;
                $("#hdnPersonnelId").val(personnelId);

                $("#txtPersonnelNo").val(personnel.PersonnelNo);
                $("#txtUserId").val(personnel.UserId);
                $("#txtName").val(personnel.Name);
                $("#sex").ligerComboBox().setValue(personnel.Sex);
                if (personnel.Photo == "" || personnel.Photo == null) {
                    $("#photo").attr("src", "/Content/images/noheader.png");
                }
                else {
                    $("#photo").attr("src", personnel.Photo);
                    $("#hdnPhoto").val(personnel.Photo);
                    $("#divUploadPhoto").css('margin-left', 12);
                    $("#divDelPhoto").show();
                }
                $("#txtBirthday").val(personnel.Birthday);
                $("#txtAliasName").val(personnel.AliasName)
                $("#nation").ligerComboBox().setValue(personnel.Nation);
                $("#politicalStatus").ligerComboBox().setValue(personnel.PoliticalStatus);
                $("#education").ligerComboBox().setValue(personnel.Education);
                $("#hireType").ligerComboBox().setValue(personnel.HireType);
                $("#txtBirthplace").val(personnel.Birthplace);
                $("#maritalStatus").ligerComboBox().setValue(personnel.MaritalStatus);
                $("#txtFertilityStatus").val(personnel.FertilityStatus);
                $("#txtIdCardNo").val(personnel.IdCardNo);
                $("#txtAddress").val(personnel.Address);
                $("#txtTelephone").val(personnel.Telephone);
                $("#txtEmergencyContact").val(personnel.EmergencyContact);
                $("#txtEmergencyPhone").val(personnel.EmergencyPhone);
                $("#txtInDate").val(personnel.InDate);
                $("#txtHeight").val(personnel.Height);
                $("#shoeSize").ligerComboBox().setValue(personnel.ShoeSize);
                $("#txtJobCode").val(personnel.JobCode);
                $("#positionCode").ligerComboBox().setValue(personnel.PositionCode);
                $("#energyLevel").ligerComboBox().setValue(personnel.EnergyLevel);
                $("#txtNursingStartDate").val(personnel.NursingStartDate);
                $("#nursingAge").ligerComboBox().setValue(personnel.NursingAge);
                $("#inServiceStatus").ligerComboBox().setValue(personnel.InServiceStatus);
                $('input:radio[name="isHszyzs"][value=' + personnel.IsHszyzs + ']').attr('checked', 'true').click();
                $("#txtHszyzsCode").val(personnel.HszyzsCode);
                $("#hdnHszyzsUrl").val(personnel.HszyzsUrl);
                if (personnel.HszyzsUrl != "" && personnel.HszyzsUrl != null) {
                    $("#showHszyzs").attr("src", personnel.HszyzsUrl);
                    $("#divHszyzs").prev().hide();
                    $("#divHszyzs").show();
                }
                $('input:radio[name="isZkhszs"][value=' + personnel.IsZkhszs + ']').attr('checked', 'true').click();
                $("#txtZkhszsTitle").val(personnel.ZkhszsTitle);
                $("#hdnZkhszsUrl").val(personnel.ZkhszsUrl);
                if (personnel.ZkhszsUrl != "" && personnel.ZkhszsUrl != null) {
                    $("#showZkhszs").attr("src", personnel.ZkhszsUrl);
                    $("#divZkhszs").prev().hide();
                    $("#divZkhszs").show();
                }

                $(".uploadify,.uploadFile_button").hide();

                //绑定工作经历
                var workExperienceList = d.Body.P_WorkExperience;
                if (workExperienceList.length == 0) { tr = addTr("workExperience", 2); }
                for (var i = 0; i < workExperienceList.length; i++) {
                    var item = workExperienceList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#workExperience tr:eq(2)");
                    }
                    else {
                        tr = addTr("workExperience");
                    }
                    tr.find("#txtStartDate").val(item.StartDate);
                    tr.find("#txtEndDate").val(item.EndDate);
                    tr.find("#txtCompanyName").val(item.CompanyName);
                    tr.find("#txtDepartment").val(item.Department);
                    tr.find("#txtJobTitle").val(item.JobTitle);
                    if ($("#hdnPageType").val() == 0) {
                        if (!(personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0)) {
                            tr.find("#addImg").hide();
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定调动记录
                var transferList = d.Body.P_TransferRecord;
                if (transferList.length == 0) { tr = addTr("transfer", 2); }
                for (var i = 0; i < transferList.length; i++) {
                    var item = transferList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#transfer tr:eq(2)");
                    }
                    else {
                        tr = addTr("transfer");
                    }
                    tr.find("#txtDate").val(item.Date);
                    tr.find("#reason").val(item.Reason);
                    tr.find("#txtInDepartment").val(item.InDepartment);
                    tr.find("#txtOutDepartment").val(item.OutDepartment);
                    tr.find("#txtRemarks").val(item.Remarks);
                    if ($("#hdnPageType").val() == 0) {
                        if (!(personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0)) {
                            tr.find("#addImg").hide();
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定能级晋升
                var nurseLevelList = d.Body.P_NurseLevelRecord;
                if (nurseLevelList.length == 0) { tr = addTr("nurseLevel", 2); }
                for (var i = 0; i < nurseLevelList.length; i++) {
                    var item = nurseLevelList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#nurseLevel tr:eq(2)");
                    }
                    else {
                        tr = addTr("nurseLevel");
                    }
                    tr.find("#txtDepartment").val(item.Department);
                    tr.find("#txtNurseLevel").val(item.NurseLevel);
                    tr.find("#txtStartDate").val(item.StartDate);
                    tr.find("#txtEndDate").val(item.EndDate);
                    tr.find("#txtRemarks").val(item.Remarks);
                    if ($("#hdnPageType").val() == 0) {
                        if (!(personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0)) {
                            tr.find("#addImg").hide();
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定培训进修
                var trainingList = d.Body.P_TrainingRecord;
                if (trainingList.length == 0) { tr = addTr("training", 2); }
                for (var i = 0; i < trainingList.length; i++) {
                    var item = trainingList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#training tr:eq(2)");
                    }
                    else {
                        tr = addTr("training");
                    }
                    tr.find("#txtStartDate").val(item.StartDate);
                    tr.find("#txtEndDate").val(item.EndDate);
                    tr.find("#txtPlace").val(item.Place);
                    tr.find("#txtTitle").val(item.Title);
                    tr.find("#txtOrganizer").val(item.Organizer);
                    tr.find("#txtRemarks").val(item.Remarks);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('training', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定论文发表
                var paperList = d.Body.P_PaperRecord;
                if (paperList.length == 0) { tr = addTr("paper", 2); }
                for (var i = 0; i < paperList.length; i++) {
                    var item = paperList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#paper tr:eq(2)");
                    }
                    else {
                        tr = addTr("paper");
                    }
                    tr.find("#txtTitle").val(item.Title);
                    tr.find("#txtPeriodicalName").val(item.PeriodicalName);
                    tr.find("#txtYearRollPage").val(item.YearRollPage);
                    tr.find("#txtAuthor").val(item.Author);
                    tr.find("#txtPeriodicalLevel").val(item.PeriodicalLevel);
                    tr.find("#txtCategory").val(item.Category);
                    tr.find("#txtCheckInTime").val(item.CheckInTime);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('paper', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定科研情况
                var researchList = d.Body.P_ResearchRecord;
                if (researchList.length == 0) { tr = addTr("research", 2); }
                for (var i = 0; i < researchList.length; i++) {
                    var item = researchList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#research tr:eq(2)");
                    }
                    else {
                        tr = addTr("research");
                    }
                    tr.find("#txtProjectNo").val(item.ProjectNo);
                    tr.find("#txtProjectName").val(item.ProjectName);
                    tr.find("#txtProjectCategory").val(item.ProjectCategory);
                    tr.find("#txtOrganizer").val(item.Organizer);
                    tr.find("#txtPrincipal").val(item.Principal);
                    tr.find("#txtFunds").val(item.Funds);
                    tr.find("#txtProjectDivision").val(item.ProjectDivision);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('research', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定奖惩记录
                var rewardAndPunishList = d.Body.P_RewardAndPunishRecord;
                if (rewardAndPunishList.length == 0) { tr = addTr("rewardAndPunish", 2); }
                for (var i = 0; i < rewardAndPunishList.length; i++) {
                    var item = rewardAndPunishList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#rewardAndPunish tr:eq(2)");
                    }
                    else {
                        tr = addTr("rewardAndPunish");
                    }
                    tr.find("#txtDepartment").val(item.Department);
                    tr.find("#txtAwardLevel").val(item.AwardLevel);
                    tr.find("#txtDate").val(item.Date);
                    tr.find("#txtName").val(item.Name);
                    tr.find("#txtAmount").val(item.Amount);
                    tr.find("#txtIntegral").val(item.Integral);
                    tr.find("#txtRemarks").val(item.Remarks);
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('rewardAndPunish', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定不良记录
                var badList = d.Body.P_BadRecord;
                if (badList.length == 0) { tr = addTr("badRecord", 2); }
                for (var i = 0; i < badList.length; i++) {
                    var item = badList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#badRecord tr:eq(2)");
                    }
                    else {
                        tr = addTr("badRecord");
                    }
                    tr.find("#txtRecordTime").val(item.RecordTime);
                    tr.find("#txtScoring").val(item.Scoring);
                    tr.find("#txtRemarks").val(item.Remarks);
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('badRecord', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定外语情况
                var foreignLanguageList = d.Body.P_ForeignLanguage;
                if (foreignLanguageList.length == 0) { tr = addTr("language", 2); }
                for (var i = 0; i < foreignLanguageList.length; i++) {
                    var item = foreignLanguageList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#language tr:eq(2)");
                    }
                    else {
                        tr = addTr("language");
                    }
                    tr.find("#txtLanguage").val(item.Language);
                    tr.find("#txtGrade").val(item.Grade);
                    if ($("#hdnPageType").val() == 0) {
                        if (!(personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0)) {
                            tr.find("#addImg").hide();
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定获得荣誉
                var honorList = d.Body.P_Honor;
                if (honorList.length == 0) { tr = addTr("honor", 2); }
                for (var i = 0; i < honorList.length; i++) {
                    var item = honorList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#honor tr:eq(2)");
                    }
                    else {
                        tr = addTr("honor");
                    }
                    tr.find("#txtDate").val(item.Date);
                    tr.find("#txtProjectName").val(item.ProjectName);
                    tr.find("#txtOrganizer").val(item.Organizer);
                    tr.find("#txtRemarks").val(item.Remarks);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('honor', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定职务变动
                var jobChangesList = d.Body.P_JobChanges;
                if (jobChangesList.length == 0) { tr = addTr("jobChanges", 2); }
                for (var i = 0; i < jobChangesList.length; i++) {
                    var item = jobChangesList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#jobChanges tr:eq(2)");
                    }
                    else {
                        tr = addTr("jobChanges");
                    }
                    tr.find("#txtStartDate").val(item.StartDate);
                    tr.find("#txtEndDate").val(item.EndDate);
                    tr.find("#txtJobTitle").val(item.JobTitle);
                    tr.find("#txtPostTenure").val(item.PostTenure);
                    tr.find("#txtRemarks").val(item.Remarks);
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('jobChanges', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定新技术/项目登记
                var newTechniqueList = d.Body.P_NewTechnique;
                if (newTechniqueList.length == 0) { tr = addTr("newTechnique", 2); }
                for (var i = 0; i < newTechniqueList.length; i++) {
                    var item = newTechniqueList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#newTechnique tr:eq(2)");
                    }
                    else {
                        tr = addTr("newTechnique");
                    }
                    tr.find("#txtRegisterTime").val(item.RegisterTime);
                    tr.find("#txtDepartment").val(item.Department);
                    tr.find("#txtTitle").val(item.Title);
                    tr.find("#txtParticipant").val(item.Participant);
                    tr.find("#txtRemarks").val(item.Remarks);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('newTechnique', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定职称获得时间
                var positionList = d.Body.P_PositionRecord;
                if (positionList.length == 0) { tr = addTr("positionRecord", 2); }
                for (var i = 0; i < positionList.length; i++) {
                    var item = positionList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#positionRecord tr:eq(2)");
                    }
                    else {
                        tr = addTr("positionRecord");
                    }
                    tr.find("#txtPosition").val(item.Position);
                    tr.find("#txtHireTime").val(item.HireTime);
                    tr.find("#txtGetTime").val(item.GetTime);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('positionRecord', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定人员注册
                var registerList = d.Body.P_Register;
                for (var i = 0; i < registerList.length; i++) {
                    var item = registerList[i];
                    var div;
                    if (item.Type == 0) {
                        if (i == 0) {
                            div = $(".trRegister").first();
                        }
                        else {
                            div = registerYanXv();
                        }
                    }
                    else {
                        div = $(".trRegister").last();
                    }
                    div.find("#txtDate").val(item.Date);
                    div.find("#txtPlace").val(item.Place);
                    div.find("#txtValidity").val(item.Validity);

                    if ($("#hdnPageType").val() == 0) {
                        if (!(personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0)) {
                            div.find("#fontYanXv").hide();
                        }
                    }
                    else {
                        div.find("#fontYanXv").hide();
                    }
                }

                //绑定教育经历
                var schoolExperienceList = d.Body.P_SchoolExperience;
                if (schoolExperienceList.length == 0) { tr = addTr("schoolExperience", 2); }
                for (var i = 0; i < schoolExperienceList.length; i++) {
                    var item = schoolExperienceList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#schoolExperience tr:eq(2)");
                    }
                    else {
                        tr = addTr("schoolExperience");
                    }
                    tr.find("#txtStartDate").val(item.StartDate);
                    tr.find("#txtEndDate").val(item.EndDate);
                    tr.find("#txtSchool").val(item.School);
                    tr.find("#txtMajor").val(item.Major);
                    tr.find("#txtEducationalSystem").val(item.EducationalSystem);
                    tr.find("#txtDegree").val(item.Degree);

                    if (item.ByzsUrl != "" && item.ByzsUrl != null) {
                        tr.find(".uploadify").each(function (index) {
                            if (index == 0) {
                                showDelFile($(this).attr("id"), item.ByzsUrl);
                                $(this).parent().next().find("#hdnImgUrl").val(item.ByzsUrl);
                            }
                        });
                    }
                    if (item.XwzsUrl != "" && item.XwzsUrl != null) {
                        tr.find(".uploadify").each(function (index) {
                            if (index == 1) {
                                showDelFile($(this).attr("id"), item.XwzsUrl);
                                $(this).parent().next().find("#hdnImgUrl").val(item.XwzsUrl);
                            }
                        });
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (!(personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0)) {
                            tr.find("#addImg").hide();
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                //绑定承担社会学术职务
                var socialScienceList = d.Body.P_SocialScience;
                if (socialScienceList.length == 0) { tr = addTr("socialScience", 2); }
                for (var i = 0; i < socialScienceList.length; i++) {
                    var item = socialScienceList[i];
                    var tr;
                    if (i == 0) {
                        tr = $("#socialScience tr:eq(2)");
                    }
                    else {
                        tr = addTr("socialScience");
                    }
                    tr.find("#txtJoinDate").val(item.JoinDate);
                    tr.find("#txtOrganization").val(item.Organization);
                    tr.find("#txtHoldingPositions").val(item.HoldingPositions);
                    tr.find("#txtRemarks").val(item.Remarks);
                    tr.find("#hdnImgUrl").val(item.ImgUrl);
                    if (item.ImgUrl != "" && item.ImgUrl != null) {
                        showDelFile(tr.find(".uploadify").attr("id"), item.ImgUrl);
                    }
                    if ($("#hdnPageType").val() == 0) {
                        if (personnel.Status == 1 || personnel.Status == 2) {
                            tr.find("#addImg").hide();
                        }
                        else {
                            tr.find("#addImg").prop("onclick", null).off("click");
                            tr.find("#addImg").click(function () {
                                addTr('socialScience', 1);
                            });
                        }
                    }
                    else {
                        tr.find("#addImg").hide();
                    }
                }

                if ($("#hdnPageType").val() == 0) {
                    if (personnel.Status == 0 || personnel.Status == 3 || personnel.Status == 5 || personnelId == 0) {
                        $("#btn1").val("暂存").show().click(function () { save(personnel.Status) });
                        $("#btn2").val("提交").show().click(function () { save(1) });
                        $(".uploadify,.uploadFile_button").show();
                    }
                }
                else if ($("#hdnPageType").val() == 2) {
                    var detailsViewBtns = JSON.parse($("#hdnDetailsViewBtns").val().replace(/([^\\])'/g, '$1\"'));
                    for (var i = 0; i < detailsViewBtns.length; i++) {
                        var detailsViewBtn = detailsViewBtns[i];
                        var run = detailsViewBtn.Function + '(' + detailsViewBtn.Parameter + ')';
                        $("#btn" + (i + 1)).val(detailsViewBtn.BtnName).attr("run", run).show().click(function () { eval($(this).attr("run")) });
                    }
                }

                position();
                $("#pageloading").hide();
            }
            else if (d.Result == 0) {
                if (d.Body != "未找到用户档案资料!") {
                    $.ligerDialog.error(d.Body);
                }
                else {
                    flag = true;
                }
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });

    if (flag && $("#hdnPageType").val() == 0) {
        $.ajax({
            url: "/Personnel/EditPersonnel/GetUser?ram" + Math.random(),
            type: "post",
            data: {},
            success: function (data) {
                var d = $.parseJSON(data);
                if (d.Result == 1) {
                    var user = d.Body;
                    getPersonnelNo();
                    $("#txtUserId").val(user.UserId);
                    $("#txtName").val(user.UserName);
                    $("#txtTelephone").val(user.Telephone);
                    $("#sex").ligerComboBox().setValue(user.Sex);
                    $("#txtBirthday").val(user.Birthday);

                    $("#nation").ligerComboBox().setValue("汉族");
                    $("#hireType").ligerComboBox().setValue(0);
                    $("#politicalStatus").ligerComboBox().setValue(-1);
                    $("#education").ligerComboBox().setValue(-1);
                    $("#shoeSize").ligerComboBox().setValue(-1);
                    $("#inServiceStatus").ligerComboBox().setValue(-1);
                    $("#nursingAge").ligerComboBox().setValue(-1);
                    $("#energyLevel").ligerComboBox().setValue(-1);
                    $("#positionCode").ligerComboBox().setValue(-1);
                    $("#maritalStatus").ligerComboBox().setValue(-1);

                    $("#btn1").val("暂存").show().click(function () { save(0) });
                    $("#btn2").val("提交").show().click(function () { save(1) });

                    position();
                    $("#pageloading").hide();
                }
                else if (d.Result == 0) {
                    $.ligerDialog.error(d.Body);
                }
                else {
                    $.ligerDialog.error("程序错误");
                }
            },
            error: function () {
                $.ligerDialog.error("程序错误");
            }
        });
    }
}

function getStatusName(status) {
    $.ajax({
        url: "/Personnel/PersonnelReview/GetReviewProcess?ram" + Math.random(),
        type: "post",
        async: false,
        success: function (r) {
            var job = $.parseJSON(r);
            if (job.IncludeStatus == "" || job.IncludeStatus == null) {
                switch (status) {
                    case 0:
                        $("#fontStatus").text("待完善");
                        break;
                    case 1:
                        $("#fontStatus").text("护士长待审核");
                        break;
                    case 2:
                        $("#fontStatus").text("护理部待审核");
                        break;
                    case 3:
                        $("#fontStatus").text("护士长驳回");
                        break;
                    case 4:
                        $("#fontStatus").text("审核完成");
                        break;
                    case 5:
                        $("#fontStatus").text("护理部驳回");
                        break;
                    default:
                }
                return;
            }
            var includeStatus = job.IncludeStatus.split('|');
            var statusAlias = job.StatusAlias.split('|');
            for (var i = 0; i < includeStatus.length; i++) {
                if (includeStatus[i] == status) {
                    $("#fontStatus").text(statusAlias[i]);
                    break;
                }
            }
        }
    });
}

function position() {
    LiftEffect({
        "control1": ".lift-nav",
        "control2": ".lift",
        "target": [".t1", ".t2", ".t3", ".t4"],
        "current": "current"
    });
}

function addTr(tableName, type) {
    var tb = $("#" + tableName);
    tb.find("#addImg").remove();
    var tr;
    if (type == 2) {
        tr = $("#" + tableName + " tr:eq(2)");
    }
    else {
        tr = tb.find("tr").eq(1).clone();
    }
    var fileId = "";
    var fileIdList = [];
    tr.find("td").each(function () {
        var file = $(this).find("input[type=file]");
        if (file.length > 0) {
            fileId = file.attr("id") + new Date().getTime();
            fileIdList.push(fileId);
            file.attr("id", fileId);
        }
        if ($(this).attr("id") == "operation") {
            $(this).html('');
            if ($("#hdnPageType").val() == 0) {
                if ($("#hdnStatus").val() == 0 || $("#hdnStatus").val() == 3 || $("#hdnStatus").val() == 5 || personnelId == 0) {
                    if (type != 2) {
                        $(this).append($('<img id="delImg" src="../../Content/images/icon/12.png" style="width:15px; height:15px;" onclick="delTr(this,\'' + tableName + '\');" />'));
                    }
                    $(this).append($('<img id="addImg" src="../../Content/images/icon/11.png" style="width:15px; height:15px;" onclick="addTr(\'' + tableName + '\')" />'));
                }
            }
            if ($("#hdnStatus").val() == 4) {
                if (tableName == "training" || tableName == "paper" || tableName == "research" || tableName == "rewardAndPunish") {
                    if (type >= 1) {
                        tr.find(".uploadify,.uploadFile_button").show();
                        $(this).append($('<img id="addImg" src="../../Content/images/icon/45.png" style="width:15px; height:15px;" onclick="saveTrInfo(\'' + tableName + '\')" />'));
                    }
                    else {
                        $(this).append($('<img id="addImg" src="../../Content/images/icon/11.png" style="width:15px; height:15px;" onclick="addTr(\'' + tableName + '\')" />'));
                    }
                }
            }
        }
    });
    if (type != 2) {
        tr.show();
        tb.append(tr);
        if (fileIdList.length > 0) {
            for (var i = 0; i < fileIdList.length; i++) {
                upload(fileIdList[i]);
            }
            bindDelFile();
            bingImgShow();
        }
        position();
    }
    return tr;
}

function delTr(obj, tableName) {
    $(obj).parent().parent().remove();
    var tb = $("#" + tableName);
    if (tb.find("#addImg").length == 0) {
        tb.find("tr").eq(tb.find("tr").length - 1).find("#operation").append($('<img id="addImg" src="../../Content/images/icon/11.png" style="width:15px; height:15px;" onclick="addTr(\'' + tableName + '\')" />'));
    }
    position();
}

function upload(id) {
    var buttonText = "";
    var folderType = "";
    if (id == "photoUploadFile") {
        buttonText = "添加头像";
        folderType = "0";
    }
    else {
        buttonText = "添加附件";
        folderType = "1";
    }
    $("#" + id).uploadify({
        swf: '/Scripts/uploadify/uploadify.swf',
        uploader: '/Personnel/EditPersonnel/Upload',
        formData: { "folderType": folderType },
        height: 23,
        width: 60,
        multi: false,
        auto: true,
        buttonText: buttonText,
        buttonCursor: 'hand',
        buttonClass: 'uploadFile_button',
        fileTypeExts: '*.gif; *.jpg; *.png; *.jpeg', //文件后缀限制
        fileSizeLimit: '2MB',
        fileTypeDesc: 'Image Files',
        queueSizeLimit: 5,
        uploadLimit: 5,
        removeTimeout: 3,
        onUploadSuccess: function (file, data, response) { //上传成功
            if (id == "photoUploadFile") {
                $("#photo").attr("src", data);
                $("#hdnPhoto").val(data);
                $("#divUploadPhoto").css('margin-left', 12);
                $("#divDelPhoto").show();
            }
            else if (id == "hszyzsUploadFile") {
                $("#hdnHszyzsUrl").val(data);
                $("#showHszyzs").attr("src", data);
                $("#divHszyzs").prev().hide();
                $("#divHszyzs").show();
            }
            else if (id == "zkhszsUploadFile") {
                $("#hdnZkhszsUrl").val(data);
                $("#showZkhszs").attr("src", data);
                $("#divZkhszs").prev().hide();
                $("#divZkhszs").show();
            }
            else {
                showDelFile(id, data);
            }
        },
        onFallback: function () {
            $.ligerDialog.error("未检测到兼容版本的Flash！");
        },
        onSelectError: function (file, errorCode, errorMsg) { //选择失败
            switch (errorCode) {
                case -100:
                    $.ligerDialog.error("上传的文件数量已经超出系统限制的" + $('#uploadFile').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    $.ligerDialog.error("文件 [" + file.name + "] 大小超出系统限制的" + $('#uploadFile').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    $.ligerDialog.error("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    $.ligerDialog.error("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
        }
    });
}

function delFile(id, path) {
    $.ajax({
        url: "/Personnel/EditPersonnel/DelFile?path=" + path,
        async: false,
        type: "GET",
        cache: false,
        success: function (r) {
            var r = $.parseJSON(r);
            if (r.Result == 1) {
                if (id == "btnDelPhoto") {
                    $("#photo").attr("src", "/Content/images/noheader.png");
                    $("#hdnPhoto").val("");
                    $("#divUploadPhoto").css('margin-left', 38);
                    $("#divDelPhoto").hide();
                }
                else if (id == "btnDelHszyzs") {
                    $("#hdnHszyzsUrl").val("");
                    $("#showHszyzs").attr("src", "");
                    $("#divHszyzs").hide();
                    $("#divHszyzs").prev().show();
                }
                else if (id == "btnDelZkhszs") {
                    $("#hdnZkhszsUrl").val("");
                    $("#showZkhszs").attr("src", "");
                    $("#divZkhszs").hide();
                    $("#divZkhszs").prev().show();
                }
                else {
                    var obj = $(id);
                    obj.next("#hdnImgUrl").val("");
                    obj.next(".pimg").attr("src", "");
                    obj.parent().hide();
                    obj.parent().prev().show();
                }
            }
            else if (r.Result == 0) {
                $.ligerDialog.error(r.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}

function bindDelFile() {
    $("[tab='delFile']").click(function () {
        var id = $(this).attr("id");
        if (id == "btnDelPhoto") {
            delFile(id, $("#hdnPhoto").val());
        }
        else if (id == "btnDelHszyzs") {
            delFile(id, $("#hdnHszyzsUrl").val());
        }
        else if (id == "btnDelZkhszs") {
            delFile(id, $("#hdnZkhszsUrl").val());
        }
        else {
            delFile($(this), $(this).next("#hdnImgUrl").val());
        }
    });
}

function showDelFile(id, data) {
    var div = $("#" + id).parent().next();
    div.find("#hdnImgUrl").val(data);
    div.find(".pimg").attr("src", data);
    div.show();
    $("#" + id).parent().hide();
}

function bingImgShow() {
    $(".pimg").click(function () {
        var _this = $(this);
        imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
    });
}

function imgShow(outerdiv, innerdiv, bigimg, _this) {
    var src = _this.attr("src");
    $(bigimg).attr("src", src);//设置#bigimg元素的src属性  

    /*获取当前点击图片的真实大小，并显示弹出层及大图*/
    $("<img/>").load(function () {
        var windowW = $(window).width();//获取当前窗口宽度  
        var windowH = $(window).height();//获取当前窗口高度  
        var realWidth = this.width;//获取图片真实宽度  
        var realHeight = this.height;//获取图片真实高度  
        var imgWidth, imgHeight;
        var scale = 0.8;//缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放  

        if (realHeight > windowH * scale) {//判断图片高度  
            imgHeight = windowH * scale;//如大于窗口高度，图片高度进行缩放  
            imgWidth = imgHeight / realHeight * realWidth;//等比例缩放宽度  
            if (imgWidth > windowW * scale) {//如宽度扔大于窗口宽度  
                imgWidth = windowW * scale;//再对宽度进行缩放  
            }
        } else if (realWidth > windowW * scale) {//如图片高度合适，判断图片宽度  
            imgWidth = windowW * scale;//如大于窗口宽度，图片宽度进行缩放  
            imgHeight = imgWidth / realWidth * realHeight;//等比例缩放高度  
        } else {//如果图片真实高度和宽度都符合要求，高宽不变  
            imgWidth = realWidth;
            imgHeight = realHeight;
        }
        $(bigimg).css("width", imgWidth);//以最终的宽度对图片缩放  

        var w = (windowW - imgWidth) / 2;//计算图片与窗口左边距  
        var h = (windowH - imgHeight) / 2;//计算图片与窗口上边距  
        $(innerdiv).css({ "top": h, "left": w });//设置#innerdiv的top和left属性  
        $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg  
    }).attr("src", src);

    $(outerdiv).click(function () {//再次点击淡出消失弹出层  
        $(this).fadeOut("fast");
    });
}

function registerYanXv() {
    $(".registerYanXv").hide();
    var newDiv = $("#divRegisterAdd").clone();
    newDiv.addClass("trRegister");
    newDiv.show();
    newDiv.find("#fontYanXv").show();
    newDiv.attr("id", "");
    $("#tdRegister").append(newDiv);
    position();
    return newDiv;
}

function save(status) {
    var PersonnelNo = $("#txtPersonnelNo").val();
    var UserId = $("#txtUserId").val();
    var Name = $("#txtName").val();
    var Sex = $("#hdnSex").val();
    var Photo = $("#hdnPhoto").val();
    var Birthday = $("#txtBirthday").val();
    var AliasName = $("#txtAliasName").val()
    var Nation = $("#hdnNation").val();
    var PoliticalStatus = $("#hdnPoliticalStatus").val();
    var Education = $("#hdnEducation").val();
    var HireType = $("#hireType").val();
    var Birthplace = $("#txtBirthplace").val();
    var MaritalStatus = $("#hdnMaritalStatus").val();
    var FertilityStatus = $("#txtFertilityStatus").val();
    var IdCardNo = $("#txtIdCardNo").val();
    var Address = $("#txtAddress").val();
    var Telephone = $("#txtTelephone").val();
    var EmergencyContact = $("#txtEmergencyContact").val();
    var EmergencyPhone = $("#txtEmergencyPhone").val();
    var InDate = $("#txtInDate").val();
    var Height = $("#txtHeight").val();
    var ShoeSize = $("#hdnShoeSize").val();
    var DepartmentCode = "";
    var JobCode = $("#txtJobCode").val();
    var PositionCode = $("#hdnPositionCode").val();
    var EnergyLevel = $("#hdnEnergyLevel").val();
    var NursingStartDate = $("#txtNursingStartDate").val();
    var NursingAge = $("#hdnNursingAge").val();
    var InServiceStatus = $("#hdnInServiceStatus").val();
    var IsHszyzs = $('input:radio[name="isHszyzs"]:checked').val();
    var HszyzsCode = $("#txtHszyzsCode").val();
    var HszyzsUrl = $("#hdnHszyzsUrl").val();
    var IsZkhszs = $('input:radio[name="isZkhszs"]:checked').val();
    var ZkhszsTitle = $("#txtZkhszsTitle").val();
    var ZkhszsUrl = $("#hdnZkhszsUrl").val();

    if (IsEmpty(PersonnelNo)) {
        $.ligerDialog.error("档案号不能为空");
        $("#txtPersonnelNo").focus();
        return;
    }
    if (IsEmpty(Name)) {
        $.ligerDialog.error("姓名不能为空");
        $("#txtName").focus();
        return;
    }
    if (IsEmpty(Birthday)) {
        $.ligerDialog.error("出生年月不能为空");
        $("#txtBirthday").focus();
        return;
    }
    if (IsEmpty(IdCardNo)) {
        $.ligerDialog.error("身份证号不能为空");
        $("#txtIdCardNo").focus();
        return;
    }
    if (IsEmpty(Telephone)) {
        $.ligerDialog.error("联系电话不能为空");
        $("#txtTelephone").focus();
        return;
    }
    if (IsEmpty(Height)) {
        $.ligerDialog.error("身高不能为空");
        $("#txtHeight").focus();
        return;
    }
    if (ShoeSize == "-1") {
        $.ligerDialog.error("鞋号不能为空");
        $("#shoeSize").focus();
        return;
    }
    if (IsEmpty(JobCode)) {
        $.ligerDialog.error("职务不能为空");
        $("#txtJobCode").focus();
        return;
    }
    if (IsEmpty(NursingStartDate)) {
        $.ligerDialog.error("护龄起算时间不能为空");
        $("#txtNursingStartDate").focus();
        return;
    }
    if (NursingAge == "-1") {
        $.ligerDialog.error("请选择护龄");
        $("#txtNursingAge").focus();
        return;
    }

    ///工作经历
    var WorkExperienceList = [];
    $("#workExperience").find("tbody tr").each(function (index) {
        if (index > 1) {
            var StartDate = $(this).find("#txtStartDate").val();
            var EndDate = $(this).find("#txtEndDate").val();
            var CompanyName = $(this).find("#txtCompanyName").val();
            var Department = $(this).find("#txtDepartment").val();
            var JobTitle = $(this).find("#txtJobTitle").val();
            if (!(IsEmpty(StartDate) && IsEmpty(EndDate) && IsEmpty(CompanyName) && IsEmpty(Department) && IsEmpty(JobTitle))) {
                var WorkExperience = { StartDate: StartDate, EndDate: EndDate, CompanyName: CompanyName, Department: Department, JobTitle: JobTitle };
                WorkExperienceList.push(WorkExperience);
            }
        }
    });

    ///调动记录
    var TransferList = [];
    $("#transfer").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Date = $(this).find("#txtDate").val();
            var Reason = $(this).find("#reason").val();
            var InDepartment = $(this).find("#txtInDepartment").val();
            var OutDepartment = $(this).find("#txtOutDepartment").val();
            var Remarks = $(this).find("#txtRemarks").val();
            if (!(IsEmpty(Date) && IsEmpty(Reason) && IsEmpty(InDepartment) && IsEmpty(OutDepartment) && IsEmpty(Remarks))) {
                var Transfer = { Date: Date, Reason: Reason, InDepartment: InDepartment, OutDepartment: OutDepartment, Remarks: Remarks };
                TransferList.push(Transfer);
            }
        }
    });

    ///能级晋升
    var NurseLevelList = [];
    $("#nurseLevel").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Department = $(this).find("#txtDepartment").val();
            var NurseLevel = $(this).find("#txtNurseLevel").val();
            var StartDate = $(this).find("#txtStartDate").val();
            var EndDate = $(this).find("#txtEndDate").val();
            var Remarks = $(this).find("#txtRemarks").val();
            if (!(IsEmpty(Department) && IsEmpty(NurseLevel) && IsEmpty(StartDate) && IsEmpty(EndDate) && IsEmpty(Remarks))) {
                var NurseLevel = { Department: Department, NurseLevel: NurseLevel, StartDate: StartDate, EndDate: EndDate, Remarks: Remarks };
                NurseLevelList.push(NurseLevel);
            }
        }
    });

    ///培训进修
    var TrainingList = [];
    $("#training").find("tbody tr").each(function (index) {
        if (index > 1) {
            var StartDate = $(this).find("#txtStartDate").val();
            var EndDate = $(this).find("#txtEndDate").val();
            var Place = $(this).find("#txtPlace").val();
            var Title = $(this).find("#txtTitle").val();
            var Organizer = $(this).find("#txtOrganizer").val();
            var Remarks = $(this).find("#txtRemarks").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(StartDate) && IsEmpty(EndDate) && IsEmpty(Place) && IsEmpty(Title) && IsEmpty(Organizer) && IsEmpty(Remarks) && IsEmpty(ImgUrl))) {
                var Training = { StartDate: StartDate, EndDate: EndDate, Place: Place, Title: Title, Organizer: Organizer, Remarks: Remarks, ImgUrl: ImgUrl };
                TrainingList.push(Training);
            }
        }
    });

    ///论文发表
    var PaperList = [];
    $("#paper").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Title = $(this).find("#txtTitle").val();
            var PeriodicalName = $(this).find("#txtPeriodicalName").val();
            var YearRollPage = $(this).find("#txtYearRollPage").val();
            var Author = $(this).find("#txtAuthor").val();
            var PeriodicalLevel = $(this).find("#txtPeriodicalLevel").val();
            var Category = $(this).find("#txtCategory").val();
            var CheckInTime = $(this).find("#txtCheckInTime").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(Title) && IsEmpty(PeriodicalName) && IsEmpty(YearRollPage) && IsEmpty(Author) && IsEmpty(PeriodicalLevel) && IsEmpty(Category) && IsEmpty(CheckInTime) && IsEmpty(ImgUrl))) {
                var Paper = { Title: Title, PeriodicalName: PeriodicalName, YearRollPage: YearRollPage, Author: Author, PeriodicalLevel: PeriodicalLevel, Category: Category, CheckInTime: CheckInTime, ImgUrl: ImgUrl };
                PaperList.push(Paper);
            }
        }
    });

    ///科研情况
    var ResearchList = [];
    $("#research").find("tbody tr").each(function (index) {
        if (index > 1) {
            var ProjectNo = $(this).find("#txtProjectNo").val();
            var ProjectName = $(this).find("#txtProjectName").val();
            var ProjectCategory = $(this).find("#txtProjectCategory").val();
            var Organizer = $(this).find("#txtOrganizer").val();
            var Principal = $(this).find("#txtPrincipal").val();
            var Funds = $(this).find("#txtFunds").val();
            var ProjectDivision = $(this).find("#txtProjectDivision").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(ProjectNo) && IsEmpty(ProjectName) && IsEmpty(ProjectCategory) && IsEmpty(Organizer) && IsEmpty(Principal) && IsEmpty(Funds) && IsEmpty(ProjectDivision) && IsEmpty(ImgUrl))) {
                var Research = { ProjectNo: ProjectNo, ProjectName: ProjectName, ProjectCategory: ProjectCategory, Organizer: Organizer, Principal: Principal, Funds: Funds, ProjectDivision: ProjectDivision, ImgUrl: ImgUrl };
                ResearchList.push(Research);
            }
        }
    });

    ///奖惩记录
    var RewardAndPunishList = [];
    $("#rewardAndPunish").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Department = $(this).find("#txtDepartment").val();
            var AwardLevel = $(this).find("#txtAwardLevel").val();
            var Date = $(this).find("#txtDate").val();
            var Name = $(this).find("#txtName").val();
            var Amount = $(this).find("#txtAmount").val();
            var Integral = $(this).find("#txtIntegral").val();
            var Remarks = $(this).find("#txtRemarks").val();
            if (!(IsEmpty(Department) && IsEmpty(AwardLevel) && IsEmpty(Date) && IsEmpty(Name) && IsEmpty(Amount) && IsEmpty(Integral) && IsEmpty(Remarks))) {
                var RewardAndPunish = { Department: Department, AwardLevel: AwardLevel, Date: Date, Name: Name, Amount: Amount, Integral: Integral, Remarks: Remarks };
                RewardAndPunishList.push(RewardAndPunish);
            }
        }
    });

    ///不良记录
    var BadList = [];
    $("#badRecord").find("tbody tr").each(function (index) {
        if (index > 1) {
            var RecordTime = $(this).find("#txtRecordTime").val();
            var Scoring = $(this).find("#txtScoring").val();
            var Remarks = $(this).find("#txtRemarks").val();
            if (!(IsEmpty(RecordTime) && IsEmpty(Scoring) && IsEmpty(Remarks))) {
                var BadRecord = { RecordTime: RecordTime, Scoring: Scoring, Remarks: Remarks };
                BadList.push(BadRecord);
            }
        }
    });

    ///外语情况
    var ForeignLanguageList = [];
    $("#language").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Language = $(this).find("#txtLanguage").val();
            var Grade = $(this).find("#txtGrade").val();
            if (!(IsEmpty(Language) && IsEmpty(Grade))) {
                var ForeignLanguage = { Language: Language, Grade: Grade };
                ForeignLanguageList.push(ForeignLanguage);
            }
        }
    });

    ///获得荣誉
    var HonorList = [];
    $("#honor").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Date = $(this).find("#txtDate").val();
            var ProjectName = $(this).find("#txtProjectName").val();
            var Organizer = $(this).find("#txtOrganizer").val();
            var Remarks = $(this).find("#txtRemarks").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(Date) && IsEmpty(ProjectName) && IsEmpty(Organizer) && IsEmpty(Remarks) && IsEmpty(ImgUrl))) {
                var Honor = { Date: Date, ProjectName: ProjectName, Organizer: Organizer, Remarks: Remarks, ImgUrl: ImgUrl };
                HonorList.push(Honor);
            }
        }
    });

    ///职务变动
    var JobChangesList = [];
    $("#jobChanges").find("tbody tr").each(function (index) {
        if (index > 1) {
            var StartDate = $(this).find("#txtStartDate").val();
            var EndDate = $(this).find("#txtEndDate").val();
            var JobTitle = $(this).find("#txtJobTitle").val();
            var PostTenure = $(this).find("#txtPostTenure").val();
            var Remarks = $(this).find("#txtRemarks").val();
            if (!(IsEmpty(StartDate) && IsEmpty(EndDate) && IsEmpty(JobTitle) && IsEmpty(PostTenure) && IsEmpty(Remarks))) {
                var JobChanges = { StartDate: StartDate, EndDate: EndDate, JobTitle: JobTitle, PostTenure: PostTenure, Remarks: Remarks };
                JobChangesList.push(JobChanges);
            }
        }
    });

    ///新技术/项目登记
    var NewTechniqueList = [];
    $("#newTechnique").find("tbody tr").each(function (index) {
        if (index > 1) {
            var RegisterTime = $(this).find("#txtRegisterTime").val();
            var Department = $(this).find("#txtDepartment").val();
            var Title = $(this).find("#txtTitle").val();
            var Participant = $(this).find("#txtParticipant").val();
            var Remarks = $(this).find("#txtRemarks").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(RegisterTime) && IsEmpty(Department) && IsEmpty(Title) && IsEmpty(Participant) && IsEmpty(Remarks) && IsEmpty(ImgUrl))) {
                var NewTechnique = { RegisterTime: RegisterTime, Department: Department, Title: Title, Participant: Participant, Remarks: Remarks, ImgUrl: ImgUrl };
                NewTechniqueList.push(NewTechnique);
            }
        }
    });

    ///职称获得时间
    var PositionList = [];
    $("#positionRecord").find("tbody tr").each(function (index) {
        if (index > 1) {
            var Position = $(this).find("#txtPosition").val();
            var HireTime = $(this).find("#txtHireTime").val();
            var GetTime = $(this).find("#txtGetTime").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(Position) && IsEmpty(HireTime) && IsEmpty(GetTime) && IsEmpty(ImgUrl))) {
                var Position = { Position: Position, HireTime: HireTime, GetTime: GetTime, ImgUrl: ImgUrl };
                PositionList.push(Position);
            }
        }
    });

    ///人员注册
    var RegisterList = [];
    $(".trRegister").each(function (index) {
        var Date = $(this).find("#txtDate").val();
        var Place = $(this).find("#txtPlace").val();
        var Validity = $(this).find("#txtValidity").val();
        var Type = $(this).find("#hdnRegisterType").val();
        if (!(IsEmpty(Date) && IsEmpty(Place) && IsEmpty(Validity))) {
            var Register = { Date: Date, Place: Place, Validity: Validity, Type: Type };
            RegisterList.push(Register);
        }
    });

    ///教育经历
    var SchoolExperienceList = [];
    $("#schoolExperience").find("tbody tr").each(function (index) {
        if (index > 1) {
            var StartDate = $(this).find("#txtStartDate").val();
            var EndDate = $(this).find("#txtEndDate").val();
            var School = $(this).find("#txtSchool").val();
            var Major = $(this).find("#txtMajor").val();
            var EducationalSystem = $(this).find("#txtEducationalSystem").val();
            var Degree = $(this).find("#txtDegree").val();
            var ByzsUrl = "";
            var XwzsUrl = "";
            $(this).find("[tab = 'delFile']").each(function (index) {
                if (index == 0) {
                    ByzsUrl = $(this).next("#hdnImgUrl").val();
                }
                else {
                    XwzsUrl = $(this).next("#hdnImgUrl").val();
                }
            });

            if (!(IsEmpty(StartDate) && IsEmpty(EndDate) && IsEmpty(School) && IsEmpty(Major) && IsEmpty(EducationalSystem) && IsEmpty(Degree) && IsEmpty(ByzsUrl) && IsEmpty(XwzsUrl))) {
                var SchoolExperience = { StartDate: StartDate, EndDate: EndDate, School: School, Major: Major, EducationalSystem: EducationalSystem, Degree: Degree, ByzsUrl: ByzsUrl, XwzsUrl: XwzsUrl };
                SchoolExperienceList.push(SchoolExperience);
            }
        }
    });

    ///承担社会学术职务
    var SocialScienceList = [];
    $("#socialScience").find("tbody tr").each(function (index) {
        if (index > 1) {
            var JoinDate = $(this).find("#txtJoinDate").val();
            var Organization = $(this).find("#txtOrganization").val();
            var HoldingPositions = $(this).find("#txtHoldingPositions").val();
            var Remarks = $(this).find("#txtRemarks").val();
            var ImgUrl = $(this).find("#hdnImgUrl").val();
            if (!(IsEmpty(JoinDate) && IsEmpty(Organization) && IsEmpty(HoldingPositions) && IsEmpty(Remarks) && IsEmpty(ImgUrl))) {
                var SocialScience = { JoinDate: JoinDate, Organization: Organization, HoldingPositions: HoldingPositions, Remarks: Remarks, ImgUrl: ImgUrl };
                SocialScienceList.push(SocialScience);
            }
        }
    });

    var P_Personnel = {
        ID: personnelId,
        UserId: UserId,
        PersonnelNo: PersonnelNo,
        Name: Name,
        Sex: Sex,
        Photo: Photo,
        Birthday: Birthday,
        AliasName: AliasName,
        Nation: Nation,
        PoliticalStatus: PoliticalStatus,
        Education: Education,
        HireType: HireType,
        Birthplace: Birthplace,
        MaritalStatus: MaritalStatus,
        FertilityStatus: FertilityStatus,
        IdCardNo: IdCardNo,
        Address: Address,
        Telephone: Telephone,
        EmergencyContact: EmergencyContact,
        EmergencyPhone: EmergencyPhone,
        InDate: InDate,
        Height: Height,
        ShoeSize: ShoeSize,
        DepartmentCode: DepartmentCode,
        JobCode: JobCode,
        PositionCode: PositionCode,
        EnergyLevel: EnergyLevel,
        NursingStartDate: NursingStartDate,
        NursingAge: NursingAge,
        InServiceStatus: InServiceStatus,
        IsHszyzs: IsHszyzs,
        HszyzsCode: HszyzsCode,
        HszyzsUrl: HszyzsUrl,
        IsZkhszs: IsZkhszs,
        ZkhszsTitle: ZkhszsTitle,
        ZkhszsUrl: ZkhszsUrl,
        Status: status
    }
    var dataJson = {
        P_Personnel: P_Personnel,
        P_WorkExperience: WorkExperienceList,
        P_TransferRecord: TransferList,
        P_NurseLevelRecord: NurseLevelList,
        P_PaperRecord: PaperList,
        P_ResearchRecord: ResearchList,
        P_RewardAndPunishRecord: RewardAndPunishList,
        P_TrainingRecord: TrainingList,
        P_BadRecord: BadList,
        P_ForeignLanguage: ForeignLanguageList,
        P_Honor: HonorList,
        P_JobChanges: JobChangesList,
        P_NewTechnique: NewTechniqueList,
        P_PositionRecord: PositionList,
        P_Register: RegisterList,
        P_SchoolExperience: SchoolExperienceList,
        P_SocialScience: SocialScienceList
    }
    $.ajax({
        url: "/Personnel/EditPersonnel/Save",
        type: 'post',
        data: JSON.stringify(dataJson),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var d = $.parseJSON(data);
            if (d.Result == 1) {
                personnelId = d.Body.Id;
                $("#hdnPersonnelId").val(personnelId);
                getStatusName(d.Body.Status);
                $.ligerDialog.success("保存成功")
            }
            else if (d.Result == 0) {
                $.ligerDialog.error(d.Body);
            }
            else {
                $.ligerDialog.error("程序错误");
            }
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}

function review(status) {
    $.ligerDialog.open({
        height: 300,
        width: 400,
        title: '请填写审核理由',
        url: '/Personnel/PersonnelReview/Review',
        showMax: false,
        showToggle: false,
        showMin: false,
        isResize: false,
        slide: false,
        data: { id: personnelId, status: status },
        buttons: [{
            text: '回调函数', onclick: function (i, d) {
                $("#btnBack").click();
            }

        }]
    });
    $(".l-dialog-buttons").hide();
}

function saveTrInfo(tableName) {
    var dataJson;
    var actionName = "";
    var flag = true;
    var tr = $("#" + tableName + " tr:last");

    switch (tableName) {
        case "training":
            var StartDate = tr.find("#txtStartDate").val();
            var EndDate = tr.find("#txtEndDate").val();
            var Place = tr.find("#txtPlace").val();
            var Title = tr.find("#txtTitle").val();
            var Organizer = tr.find("#txtOrganizer").val();
            var Remarks = tr.find("#txtRemarks").val();
            var ImgUrl = tr.find("#hdnImgUrl").val();
            if (IsEmpty(StartDate) || IsEmpty(EndDate) || IsEmpty(Place) || IsEmpty(Title) || IsEmpty(Organizer) || IsEmpty(Remarks) || IsEmpty(ImgUrl)) {
                $.ligerDialog.error("数据填写不完整");
                flag = false;
            }
            else {
                dataJson = { PersonnelId: personnelId, StartDate: StartDate, EndDate: EndDate, Place: Place, Title: Title, Organizer: Organizer, Remarks: Remarks, ImgUrl: ImgUrl };
                actionName = "AddTrainingRecord";
            }
            break;
        case "paper":
            var Title = tr.find("#txtTitle").val();
            var PeriodicalName = tr.find("#txtPeriodicalName").val();
            var YearRollPage = tr.find("#txtYearRollPage").val();
            var Author = tr.find("#txtAuthor").val();
            var PeriodicalLevel = tr.find("#txtPeriodicalLevel").val();
            var Category = tr.find("#txtCategory").val();
            var CheckInTime = tr.find("#txtCheckInTime").val();
            var ImgUrl = tr.find("#hdnImgUrl").val();
            if (IsEmpty(Title) || IsEmpty(PeriodicalName) || IsEmpty(YearRollPage) || IsEmpty(Author) || IsEmpty(PeriodicalLevel) || IsEmpty(Category) || IsEmpty(CheckInTime) || IsEmpty(ImgUrl)) {
                $.ligerDialog.error("数据填写不完整");
                flag = false;
            }
            else {
                dataJson = { PersonnelId: personnelId, Title: Title, PeriodicalName: PeriodicalName, YearRollPage: YearRollPage, Author: Author, PeriodicalLevel: PeriodicalLevel, Category: Category, CheckInTime: CheckInTime, ImgUrl: ImgUrl };
                actionName = "AddPaperRecord";
            }
            break;
        case "research":
            var ProjectNo = tr.find("#txtProjectNo").val();
            var ProjectName = tr.find("#txtProjectName").val();
            var ProjectCategory = tr.find("#txtProjectCategory").val();
            var Organizer = tr.find("#txtOrganizer").val();
            var Principal = tr.find("#txtPrincipal").val();
            var Funds = tr.find("#txtFunds").val();
            var ProjectDivision = tr.find("#txtProjectDivision").val();
            var ImgUrl = tr.find("#hdnImgUrl").val();
            if (IsEmpty(ProjectNo) || IsEmpty(ProjectName) || IsEmpty(ProjectCategory) || IsEmpty(Organizer) || IsEmpty(Principal) || IsEmpty(Funds) || IsEmpty(ProjectDivision) || IsEmpty(ImgUrl)) {
                $.ligerDialog.error("数据填写不完整");
                flag = false;
            }
            else {
                dataJson = { PersonnelId: personnelId, ProjectNo: ProjectNo, ProjectName: ProjectName, ProjectCategory: ProjectCategory, Organizer: Organizer, Principal: Principal, Funds: Funds, ProjectDivision: ProjectDivision, ImgUrl: ImgUrl };
                actionName = "AddResearchRecord";
            }
            break;
        case "rewardAndPunish":
            var Department = tr.find("#txtDepartment").val();
            var AwardLevel = tr.find("#txtAwardLevel").val();
            var Date = tr.find("#txtDate").val();
            var Name = tr.find("#txtName").val();
            var Title = tr.find("#txtTitle").val();
            var Amount = tr.find("#txtAmount").val();
            var Integral = tr.find("#txtIntegral").val();
            var Remarks = tr.find("#txtRemarks").val();
            if (IsEmpty(Department) || IsEmpty(AwardLevel) || IsEmpty(Date) || IsEmpty(Name) || IsEmpty(Title) || IsEmpty(Amount) || IsEmpty(Integral) || IsEmpty(Remarks)) {
                $.ligerDialog.error("数据填写不完整");
                flag = false;
            }
            else {
                dataJson = { PersonnelId: personnelId, Department: Department, AwardLevel: AwardLevel, Date: Date, Name: Name, Title: Title, Amount: Amount, Integral: Integral, Remarks: Remarks };
                actionName = "AddRewardAndPunishRecord";
            }
            break;
    }
    if (flag) {
        $.ajax({
            url: "/Personnel/EditPersonnel/" + actionName,
            type: 'post',
            data: JSON.stringify(dataJson),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var d = $.parseJSON(data);
                if (d.Result == 1) {
                    var obj = tr.find("#addImg").parent();
                    tr.find("#addImg").remove();
                    tr.find(".uploadify,.uploadFile_button").hide();
                    obj.append($('<img id="addImg" src="../../Content/images/icon/11.png" style="width:15px; height:15px;" onclick="addTr(\'' + tableName + '\',1)" />'));
                    $.ligerDialog.success("保存成功")
                }
                else if (d.Result == 0) {
                    $.ligerDialog.error(d.Body);
                }
                else {
                    $.ligerDialog.error("程序错误");
                }
            },
            error: function () {
                $.ligerDialog.error("程序错误");
            }
        });
    }
}

